#!/bin/bash
set -e

cd packages/react

# Add base url to be able to serve static files
if [ -n "$1" ]; then
  echo '<base href="/storybook/" />' >> .storybook/manager-head.html
else
  echo '<base href="/react/storybook/" />' >> .storybook/manager-head.html
fi

# Build storybook inside docs
npx storybook build -o ../../docs/public/storybook

# Move index page to the right location
cp .storybook/index.html ../../docs/public/index.html

# Remove manager-head after build to not interfere with dev builds
rm .storybook/manager-head.html